Tee

In [32]:
echo hi | cat
hi
In [33]:
echo hi | cat > /root/file
echo hi > /root/file
bash: /root/file: Permission denied
bash: /root/file: Permission denied

In [ ]:
# Wrong echo hi sudo > /root/file
# Wrong sudo echo hi > /root/file
# Wrong sudo echo hi | sudo cat > /root/file
In [1]:
echo hi | tee tfile
hi
In [2]:
cat tfile
hi
In [ ]:
echo hi | sudo tee /root/file # Correct
echo hi | sudo tee /root/file > /dev/null # if you don't wanna see the output
In [10]:
# see whats happening between commands
cat tfile | sort | uniq -d | head -3 | grep -iv "Milad" > z; cat < z;

# lets say some thing is wrong
cat tfile | sort | tee check | uniq -d | head -3 | grep -iv "Milad" > z; cat < z;
cat check
hi

Lecture notes

License

Creative Commons License

Linux Notes by Milad As (Ravexina) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.


ravexina's gitlab

ravexina's github